/*
 * hsourceobject.c
 *
 *  Created on: Apr 7, 2012
 *      Author: benoybose
 */

#include "hcsrcobj.h"
#include <stdio.h>
#include <string.h>
#include <gc.h>

const int HSOURCE_OBJECT_TYPE_INVALID = 0;
const int HSOURCE_OBJECT_TYPE_CODE = 1;
const int HSOURCE_OBJECT_TYPE_LIB = 2;

const char* EXTENSION_SOURCE = ".hoo";
const char* EXTENSION_LIBRARY = ".hol";

hcsrcobj* hcsrcobj_create(const char* fileName, const char* extension) {
    int type = HSOURCE_OBJECT_TYPE_INVALID;
    type = HSOURCE_OBJECT_TYPE_INVALID;
    if (0 == strcmp(extension, EXTENSION_SOURCE)) {
        type = HSOURCE_OBJECT_TYPE_CODE;
    } else if (0 == strcmp(extension, EXTENSION_LIBRARY)) {
        type = HSOURCE_OBJECT_TYPE_LIB;
    }

    if (type) {
        hcsrcobj* pObject = (hcsrcobj*) GC_MALLOC(sizeof (hcsrcobj));
        pObject->type = type;
        pObject->filename = hcstring_create(fileName);
        return pObject;
    } else {
        return 0;
    }
}

void hsource_obj_print(void* ptr) {
    hcsrcobj* pItem = (hcsrcobj*) ptr;
    printf("Filename: %s; Type: %d\n", pItem->filename->text, pItem->type);
}

